package com.hawthorn.admin.constant;

import com.hawthorn.component.constant.DicConstant;

import java.util.Map;

/**
 * <p>todo 自定义表选字典配置类</p>
 * @author: andyten@tom.com | xukaixing@hotmail.com
 * @created: 2021/12/9 6:04 PM
 * @version v1.0.4
 * @copyright: Copyright (c)  andyten
 */
public class TableDicConstant
{
  public static String getTableDic(Map<String, Object> user, String vparam)
  {
    String ret = "";
    String[] arr = {};
    String type;
    //存放参数
    String param = "";
    // 额外的参数，可以用多个逗号分开
    String[] paramsArr = new String[1];
    if (vparam.contains(":"))
    {
      paramsArr = vparam.split(":");
      type = paramsArr[0];
    } else
      type = vparam;
    //新增截取参数
    if (vparam.indexOf(",") != -1)
    {
      int index = vparam.indexOf(",");
      String[] params = vparam.split(",");
      if (params.length >= 2)
      {
        type = params[0];
        param = vparam.substring(index + 1);
      }
    }
    switch (type)
    {
      case "FUNC-USER-USERID":
        ret = "sys_user:account:user_name[id,mobile]{sex,del_flag}:1=1";
        break;
      case "FUNC-COMPANY-COMPANYID":
        ret = "sys_company:id:sname[code]:1=1 and status= " + DicConstant.YXBS_01;
        break;
      case "FUNC-DEPT-DEPTID":
        ret = "sys_dept:id:dname[dcode]:1=1 and status= " + DicConstant.YXBS_01;
        if (paramsArr != null && paramsArr.length > 1 && paramsArr[1] != null)
          ret += " and " + paramsArr[1];
        break;
      case "FUNC-DIVISION-DIVISIONID":
        ret = "sys_division:code:dname{id}:1=1";
        break;
      case "FUNC-MENU-CODE":
        ret = "sys_menu:code:title{id}:type!=2";
        break;
      case "FUNC-USER-ROLEID":
        ret = "sys_role r left join sys_dict d on r.level = d.dic_code:r.id:r.rname[r.rcode, d.label]:1=1 and r.status= " + DicConstant.YXBS_01;
        break;
      case "FUNC-DEALER-USER-ROLEID":
        ret = "sys_role r left join sys_dict d on r.level = d.dic_code:r.id:r.rname[r.rcode, d.label]:1=1 and r.status= " + DicConstant.YXBS_01 + " " + param + "  or r.rcode in ('dealerWaremng','dealerInternal','dealerSalesman')";
        break;
    }
    return ret;
  }
}
